package ifi.card.main;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;

public class Setting extends SubScreenActivity implements OnSeekBarChangeListener {
	public static final String PREF_FILE = "behoctienganh_pref";
	public static final String BG_MUSIC_VOLUME_KEY = "bgMusicVol";
	private SharedPreferences pref;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.setContentView(R.layout.setting);
		((SeekBar) (findViewById(R.id.SoundSeekBar)))
				.setOnSeekBarChangeListener(this);
		((SeekBar) (findViewById(R.id.SoundSeekBar)))
				.setMax((int) (Audio.MAX_VOLUME * 100));
		((SeekBar) (findViewById(R.id.SoundSeekBar))).setProgress((int) (Audio
				.getVolume(R.raw.gameframe) * 100));

		pref = getSharedPreferences(PREF_FILE, MODE_PRIVATE);
	}

	@Override
	public void onProgressChanged(SeekBar seekBar, int progress,
			boolean fromUser) {
		float currentVolume = (float) (seekBar.getProgress())
				/ (float) seekBar.getMax();
		Audio.setVolume(R.raw.gameframe, currentVolume);
	}

	@Override
	public void onStartTrackingTouch(SeekBar seekBar) {
		// TODO Auto-generated method stub

	}

	@Override
	public void onStopTrackingTouch(SeekBar seekBar) {
		// TODO Auto-generated method stub

	}
	@Override
	public void onPause() {
		SharedPreferences.Editor editor = pref.edit();
		editor.putFloat(BG_MUSIC_VOLUME_KEY, Audio.getVolume(R.raw.gameframe));
		editor.commit();
		super.onPause();
	}
}
